﻿@{
    ViewBag.Title = "综合文档管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section head{
    <style type="text/css">
        div#navigation
        {
            background: white;
        }
        div#wrapper
        {
            float: right;
            width: 100%;
            margin-left: -235px;
        }
        div#content
        {
            margin-left: 235px;
        }
        div#navigation
        {
            float: left;
            width: 230px;
        }
        .datagrid-cell a
        {
            color: black;
        }
        .datagrid-cell a:hover
        {
            color: red;
        }
    </style>
}
@section scripts{
    <script src="~/Areas/qms/ViewModels/qms.FileContent.js"></script>
    <script type="text/javascript">
        var vmInstance;
        using("lookup", easyuifix.datagrid_editor_extend); //动态载入这些组件
        using(['datagrid','validatebox','messager']);
        var data = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model));
        vmInstance = new viewModel(data);
        ko.bindingViewModel(vmInstance); 
        //
//        setTimeout(initUploader,100);
        //删除文件
        var  DeleteFile = function(d)
        {
            com.message('confirm', "确定要删除所选中的文件吗?", function (b) {
                if (b) {
                    com.ajax({
                        type: 'DELETE', 
                        url:"/qms/FileContent/DeleteFile?id=" + d,
                        success: function (d) {
                           if (d.success == true)
                           {
                                com.message('success', "删除成功");
                                vmInstance.refreshClick();
                           }
                           else
                           {
                                com.message('error', d.message);
                            }
                        }
                    });
                }
            });
        };
        //格式化单元格样式
        var  cellStyler = function(value,row,index){
            ////styler="cellStyler"
            if (row["ApproveState"].replace(/(^\s*)|(\s*$)/g, "") == "passed")
            {
                return 'background-color:#CCFF33;color:#FF0000;';
            }
        };
        var formatterPic = function(value,row)
        {
        var html = "";
          if (row["ApproveState"].replace(/(^\s*)|(\s*$)/g, "") == "passed")
              html = '<a href="#"  style="margin-left:2px"><span class="icon icon-user-accept ">&nbsp;</span>[已发布]</a>';
          else
              html = '<a href="#"  style="margin-left:2px"><span class="icon icon-book">&nbsp;</span>[未发布]</a>';
        if (row["FileContent_IsPublic"] == 0 ) 
            html += '<a href="#"  style="margin-left:2px"><span class="icon icon-user ">&nbsp;</span>[私有]</a>';
          return html;
        }


        var formatterPermit = function (value, row) {
            if (row["_isnew"] == true) return;
            var  html="";
//            var arrayObj = row["FileContent_Fjsl"].replace(new RegExp("<FileAttachment_RowId>","gm"),"").split("</FileAttachment_RowId>");
            var arrayObj = row["FileContent_Fjsl"].split('*');
            for (var i = 0; i < arrayObj.length; i++) {
                var sObj = arrayObj[i].split('|'); //由行号和文件名组成 JSON.stringify(sObj[0]);   
                if (sObj[0] <= 0 ) continue;
                    var Bh =  row["FileContent_FileBh"] + '|'+sObj[0];
                    //var  html = '<a href="#" onclick=\'fundownload(' + JSON.stringify(row) + ')\' style="margin-left:2px"><span class="icon icon-download ">&nbsp;</span>[下载]</a>';
                    //html +='<a href="" onclick=\'fundownload(' + Bh+ ')\' style="margin-left:2px"><span class="icon icon-download ">&nbsp;</span>[下载] ...' + sObj[1]+ '</a><br>';
                    html +='<a href="javascript:void(0)" onclick=\'DeleteFile(' + JSON.stringify(Bh) + ')\' + style="margin-left:2px" <span class="icon icon-delete0"></span>删除</a>&nbsp  <a href="/qms/FileContent/DownLoad?id=' + Bh + '"+  style="margin-left:2px"><span class="icon icon-download ">&nbsp;</span>[下载]&nbsp&nbsp' + sObj[1]+ '</a><br>';
            }
            return html;
        };
    </script>
}
<div id="container">
    <div id="wrapper">
        <div id="content">
            <div class="z-toolbar">
                <a id="a_refresh" href="#" plain="true" class="easyui-linkbutton" icon="icon-arrow_refresh" title="刷新" data-bind="click:refreshClick">刷新</a> 
                <a id="a_add" href="#" plain="true" class="easyui-linkbutton" icon="icon-add"   title="新增" data-bind="click:addClick">新增</a>
                <a id="a_edit" href="#" plain="true" class="easyui-linkbutton" icon="icon-edit" title="编辑" data-bind="click:editClick">编辑</a> 
                <a id="a_del" href="#" plain="true" class="easyui-linkbutton" icon="icon-cross" title="删除" data-bind="click:deleteClick">删除</a> 
                <a id="a_publish" href="#" plain="true" class="easyui-linkbutton" icon="icon-accept" title="发布" data-bind="click:publishClick">发布</a> 
                <a id="a_type" href="#" plain="true" class="easyui-linkbutton" icon="icon-node_tree" data-bind="click:typeClick" title="文档类别">文档类别</a>
            </div>
            @* @Html.RenderToolbar()*@
             <div id="condition" class="container_12" style="position:relative;">
          
            <div class="grid_2 lbl">文档名称</div>
            <div class="grid_2 val"><input type="text" data-bind="value:form.FileContent_Title" class="z-txt"/></div>
            <div class="grid_2 lbl">是否公开</div>
            <div class="grid_2 val"><input type="text" data-bind="datasource:dataSource.publicItems ,comboboxValue:form.FileContent_IsPublic" class="z-txt easyui-combobox" data-options="showblank:true"/></div>
            <div class="clear"></div>
            <div class="grid_2 lbl">有效日期</div>
            <div class="grid_2 val"><input type="text" data-bind="dateboxValue:form.FileContent_ValidDate" class="z-txt easyui-datebox"/></div>
            <div class="grid_2 lbl">是否发布</div>
            <div class="grid_2 val"><input type="text" data-bind="datasource:dataSource.ApproveStateItems ,comboboxValue:form.ApproveState" class="z-txt easyui-combobox" data-options="showblank:true"/></div>
            <div class="clear"></div>
            <div class="prefix_9" style="position:absolute;top:5px;height:0;">  
                <a id="a_search" href="#" class="button button-blue" style="margin:0 15px;" data-bind="click:searchClick">查询</a> 
                <a id="a_reset" href="#" class="button button-blue" data-bind="click:clearClick">清空</a>
            </div>
        </div>
            <table id="gridlist" data-bind="datagrid:grid">
                <thead>
                    <tr>
                        <th field="Pic" align="left" width="130" formatter="formatterPic">说明</th>
                        <th field="CreateDate" sortable="true" align="center" width="80"  formatter="com.formatDate">建档日期</th>
                        <th field="FileContent_FileBh" hidden="true" align="left" width="100" editor="{type:'validatebox',options:{required:true}}"> 文档编号</th>
                        <th field="FileContent_TypeBh" hidden="true" sortable="true" align="left" width="100">类别编号</th>
                        <th field="FileContent_Title" sortable="true" align="left" width="150" >文档名称</th>
                        <th field="Permit" align="left" width="320" formatter="formatterPermit">附件内容</th>
                        <th field="FileContent_UserCode" sortable="true" align="left" width="80">用户</th>
                        <th field="FileContent_IsPublic"        sortable="true" align="center"  formatter="com.formatCheckbox2"   width="50"  >公开</th> 
                        <th field="FileContent_Text" sortable="true" align="left" width="150" >文档说明</th>
                        <th field="FileContent_Bmbh" editor="{type:'lookup',options:{lookupType:'organize',parentField:'pid'}}" sortable="true" align="left" width="80">单位编号</th>
                        <th field="FileContent_Bmmc" sortable="true" align="left" width="100">单位名称</th>
                        <th field="CreatePerson" sortable="true" align="center" width="80"  >建档人 </th>
                        <th field="ApproveState" sortable="true" align="center" width="50" >是否发布</th> 
                    </tr>
                </thead>
            </table>
        </div>
    </div>
    <div id="navigation">
        <div title="文档类别" style="width: 230px;" class="easyui-panel" data-options="split:true,title: '文档类别', iconCls: 'icon-node_tree', height: $(window).height() - 4 ">
            <ul data-bind="easyuiTree:tree">
            </ul>
        </div>
    </div>
</div>
<script type="text/html" id="type-template">

    <style type="text/css">
        .datagrid-wrap{border-width:0 0 1px 0;}
    </style>

    <table data-bind="treegrid:grid">
        <thead>
            <th field="_id"  hidden="true"></th>  
            <th field="FileType_Bh"        sortable="true" align="left"    width="80" editor="{type:'validatebox',options:{required:true}}">类别编码</th>
            <th field="FileType_Mc"        sortable="true" align="left"    width="140" editor="{type:'validatebox',options:{required:true}}">类别名称</th>
            <th field="FileType_UserCode"  sortable="true" align="left"    width="60"   >用户编码  </th>   
            <th field="FileType_IsPublic"   sortable="true" align="center"     width="65"  editor="{type: 'checkbox',options: {on: 'true',off: 'false'}}" formatter="com.formatCheckbox">是否公开</th>
            <th field="FileType_Remark"    sortable="true" align="right"   width="180"  editor="text">备注       </th>  
        </thead>
    </table>
    
    <div style="text-align:center;margin:5px;">
        <a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" data-bind="click:confirmClick" href="javascript:void(0)"  >确定</a>  
        <a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" data-bind="click:cancelClick" href="javascript:void(0)">取消</a> 
    </div>
</script>
